package com.piggy.logi.sys.api;

import com.piggy.common.core.constant.SecurityConstants;
import com.piggy.common.core.constant.ServiceNameConstants;
import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.logi.sys.api.domain.LogiSysUser;
import com.piggy.logi.sys.api.factory.RemoteLogiUserFallbackFactory;
import com.piggy.sys.api.model.LoginUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户服务
 *
 * @author shark
 */
@FeignClient(contextId = "remoteLogiUserService", value = ServiceNameConstants.SYSTEM_LOGI_SERVICE, fallbackFactory = RemoteLogiUserFallbackFactory.class)
public interface RemoteLogiUserService {

    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名
     * @param source   请求来源
     * @return 结果
     */
    @GetMapping("/logi/user/info/{username}")
    public R<LoginUser<LogiSysUser>> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/phone/{phone}")
    public R<LoginUser<LogiSysUser>> getUserByPhone(@PathVariable("phone") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/email/{email}")
    public R<LoginUser<LogiSysUser>> getUserByEmail(@PathVariable("email") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名
     * @param source   请求来源
     * @return 结果
     */
    @GetMapping("/logi/user/dept/{username}")
    public R<LoginUser<LogiSysUser>> getUserInfoByDept(@PathVariable("username") String username,
                                                       @RequestParam("dept") String dept,
                                                       @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/dept/phone/{phone}")
    public R<LoginUser<LogiSysUser>> getUserByPhoneByDept(@PathVariable("phone") String phone,
                                                          @RequestParam("dept") String dept,
                                                          @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/resetPwd/{phone}")
    public R<Integer> resetPwd(@PathVariable("phone") String phone,
                               @RequestParam("dept") String dept,
                               @RequestParam("passwd") String passwd,
                               @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/resetMainUserPwd/{phone}")
    public R<Integer> resetMainUserPwd(@PathVariable("phone") String phone,
                               @RequestParam("passwd") String passwd,
                               @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/getMainUser/{phone}")
    public R<LogiSysUser> getMainUser(@PathVariable("phone") String phone,
                                       @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/dept/email/{email}")
    public R<LoginUser<LogiSysUser>> getUserByEmailByDept(@PathVariable("email") String email,
                                                          @RequestParam("dept") String dept,
                                                          @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/sys/{username}")
    public R<LogiSysUser> getSysUser(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 注册用户信息
     *
     * @param logiSysUser 用户信息
     * @param source      请求来源
     * @return 结果
     */
    @PostMapping("/logi/user/register")
    public R<LogiSysUser> register(@RequestBody LogiSysUser logiSysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据用户id获取用户
     *
     * @param userId 用户信息id
     * @param source 请求来源
     * @return 结果
     */
    @GetMapping(value = {"/logi/user/{userId}"})
    public R<LogiSysUser> getInfo(@PathVariable(value = "userId", required = false) Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据部门获取获取用户
     *
     * @param deptId 部门id
     * @param source 请求来源
     * @return 结果
     */
    @GetMapping(value = {"/logi/user/getUser/{deptId}"})
    R<List<LogiSysUser>> getUserByDeptId(@PathVariable(value = "deptId", required = false) Long deptId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据部门列表获取用户
     *
     * @param deptIds
     * @param source
     * @return
     */
    @GetMapping("/logi/user/getUserByDeptIds")
    R<List<LogiSysUser>> getUserByDeptIds(@RequestParam("deptIds") List<Long> deptIds, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/logi/user/queryUserAll/{mainDeptId}")
    R<List<LogiSysUser>> queryUserAll(@PathVariable(value = "mainDeptId") Long mainDeptId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据手机号码列表获取用户
     *
     * @param phoneNumber
     * @param source
     * @return
     */
    @GetMapping("/logi/user/getUsersByPhoneNumber")
    R<List<LogiSysUser>> getUsersByPhoneNumber(@RequestParam("phoneNumber") String phoneNumber, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/logi/user/getUserByID")
    R<LogiSysUser> getUserByID(@RequestParam("userId") String userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/logi/user/innerList")
    public TableDataInfo<LogiSysUser> innerList(@RequestBody LogiSysUser user, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/logi/user/bossAdd")
    public R bossAdd(@Validated @RequestBody LogiSysUser user, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}
